package com.mutual.reins.verify.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.base.exception.BusinessException;
import com.mutual.reins.danger.entity.PrpReinsVerify;
import com.mutual.reins.danger.entity.PrptDangerUnit;
import com.mutual.reins.danger.service.*;
import com.mutual.reins.excessloss.entity.FeoxLayer;
import com.mutual.reins.excessloss.service.IFeoxLayerService;
import com.mutual.reins.excessloss.service.IFeoxPlanService;
import com.mutual.reins.excessloss.service.IFeoxReinsService;
import com.mutual.reins.interf.entity.*;
import com.mutual.reins.interf.service.*;
import com.mutual.reins.trial.entity.PrptReinsShare;
import com.mutual.reins.trial.service.IPrptReinsShareService;
import com.mutual.reins.trial.service.IPrptReinsTrialService;
import com.mutual.reins.utils.ReinsCompareRiskUtils;
import com.mutual.reins.utils.constraint.ReinsConst;
import com.mutual.reins.utils.constraint.UserExceptionEnum;
import com.mutual.reins.verify.service.IVerifyPrptDangerUnitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 实现再保投保单危险单位数据校验接口
 *
 * @author panchen
 * @since 2021-03-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class VerifyPrptDangerUnitServiceImpl implements IVerifyPrptDangerUnitService {

    @Autowired
    private IPrptDangerUnitService iPrptDangerUnitService;
    @Autowired
    private IPrptDangerCoinsService iPrptDangerCoinsService;
    @Autowired
    private IPrptDangerItemService iPrptDangerItemService;
    @Autowired
    private IPrptDangerTotService iPrptDangerTotService;
    @Autowired
    private IPrptDangerPlanService iPrptDangerPlanService;

    @Autowired
    private IReinsPolicyInterfService iReinsPolicyInterfService;
    @Autowired
    private IReinsPolicyUnitService  iReinsPolicyUnitService;
    @Autowired
    private IPrptReinsTrialService iPrptReinsTrialService;
    @Autowired
    private IPrptReinsShareService iPrptReinsShareService;
    @Autowired
    private IFeoEnquiryService iFeoEnquiryService;
    @Autowired
    private IPrpReinsVerifyService iPrpReinsVerifyService;
    @Autowired
    private IPrpReinsNotionService iPrpReinsNotionService;
    @Autowired
    private IReinsPolicyCededService iReinsPolicyCededService;
    @Autowired
    private IReinsInterFlogService iReinsInterFlogService;
    @Autowired
    private IFeoEngageService iFeoEngageService;
    @Autowired
    private IFeoTotService iFeoTotService;
    @Autowired
    private IFeoCoinsService iFeoCoinsService;
    @Autowired
    private IFeoItemService iFeoItemService;
    @Autowired
    private IFeoReinsReceiveService iFeoReinsReceiveService;
    @Autowired
    private IFeoReinsVerifyService iFeoReinsVerifyService;
    @Autowired
    private IFeoxLayerService iFeoxLayerService;
    @Autowired
    private IFeoxPlanService iFeoxPlanService;
    @Autowired
    private IFeoxReinsService iFeoxReinsService;



    /**
     * 再保投保单危险单位数据校验
     * @param cerTiNo 承保送再保信息
     * @param cerTiType 校验类型（投保单）
     * @return 返回核校验结果信息对象
     */
    @Override
    public ReinsCheckDto reinsCheckData(String cerTiNo, String cerTiType){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        log.info("{}审核通过前数据校验调入时间：{}",cerTiNo,LocalDateTime.now().format(dateTimeFormatter));
        ReinsCheckDto reinsCheckDto = new ReinsCheckDto();
        try {
            // 初始化双核审核通过前对再保数据校验返回信息
            reinsCheckDto.setCerTiNo(cerTiNo);
            reinsCheckDto.setCerTiType(cerTiType);
            reinsCheckDto.setStatusType("Y");
            reinsCheckDto.setStatusDesc("再保处理成功");
            checkReinsData(cerTiNo,cerTiType);

        } catch (BusinessException | IllegalAccessException e) {
            reinsCheckDto.setStatusType("N");
            reinsCheckDto.setStatusDesc(e.getMessage());
            throw new BusinessException(UserExceptionEnum.REINS_REINSCHECKDATA.getCode(), UserExceptionEnum.REINS_REINSCHECKDATA.getMessage(), this.getClass().getName() + ".reinsCheckData(" + cerTiNo + ")");
        }
        log.info("{}审核通过前数据校验调出时间：{}",cerTiNo,LocalDateTime.now().format(dateTimeFormatter));
        return reinsCheckDto;
    }

    /**
     * 再保投保单下发修改数据校验
     *
     * @param reinsDeleteDto 下发修改对象
     * @return 核心提交核保调用再保接口返回信息对象
     */
    @Override
    public ReinsStatusDto deleteReinsData(ReinsDeleteDto reinsDeleteDto) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        log.info("下发修改调入时间：{}", LocalDateTime.now().format(dateTimeFormatter));
        ReinsStatusDto reinsStatusDto = new ReinsStatusDto();
        ReinsInterFlog reinsInterFlog = new ReinsInterFlog();
        try {
            // 初始化返回状态
            reinsStatusDto.setCerTiNo(reinsDeleteDto.getCerTiNo());
            reinsStatusDto.setCerTiType(reinsDeleteDto.getCerTiType());
            reinsStatusDto.setStatus("Y");

            reinsInterFlog.setCerTiNo(reinsDeleteDto.getCerTiNo());
            reinsInterFlog.setCerTiType(reinsDeleteDto.getCerTiType());
            reinsInterFlog.setOperatorCode(reinsDeleteDto.getOperatorCode());
            reinsInterFlog.setOperatorName(reinsDeleteDto.getOperatorName());
            reinsInterFlog.setOperatorDate(LocalDate.parse(reinsDeleteDto.getOperatorDateStr(), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            // 初始化日志表时，日志表处理状态默认为不通过状态
            reinsInterFlog.setRecordFlag("0");
            if (ReinsConst.CERTITYPE_PRPT.equals(reinsDeleteDto.getCerTiType())) {
                deletePolicyData(reinsDeleteDto,reinsInterFlog);
            } else {
                reinsStatusDto.setStatus("N");
            }

        } catch (BusinessException e) {
            reinsStatusDto.setStatus("N");
            throw new BusinessException(UserExceptionEnum.REINS_DELETEREINSDATA.getCode(), UserExceptionEnum.REINS_DELETEREINSDATA.getMessage(), this.getClass().getName() + ".deleteReinsData(" + reinsDeleteDto.getCerTiNo() + ")");
        }
        log.info("下发修改调出时间：{}", LocalDateTime.now().format(dateTimeFormatter));
        return reinsStatusDto;
    }

    /**
     * 双核控制再保自留信息
     *
     * @param cerTiNo   承保送再保信息
     * @param cerTiType 校验类型（投保单）
     * @return 返回自留额
     */
    @Override
    public String checkRetentionValue(String cerTiNo, String cerTiType) {
        log.info("自留额控制begin：当前业务号{}" , cerTiNo);
        String retentionValue = "";
        try {
            retentionValue = shareRetentionValue(cerTiNo,cerTiType);
            log.info("自留额控制end：当前业务号{}" + cerTiNo);
        } catch (BusinessException e) {
            throw new BusinessException(UserExceptionEnum.REINS_CHECKRETENTIONVALUE.getCode(), UserExceptionEnum.REINS_CHECKRETENTIONVALUE.getMessage(), this.getClass().getName() + ".checkRetentionValue(" + cerTiNo + ")");
        }
        return retentionValue;
    }

    /**
     * 自动核保，自留额+附加自留额 校验
     *
     * @param cerTiNo   承保送再保信息
     * @param cerTiType 校验类型（投保单）
     * @return 返回校验结果信息对象
     */
    @Override
    public ReinsCheckDto checkReinsRetentionData(String cerTiNo, String cerTiType) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        log.info("{}自动核保审核通过前数据校验调入时间：{}" ,cerTiNo, LocalDateTime.now().format(dateTimeFormatter));
        ReinsCheckDto reinsCheckDto = new ReinsCheckDto();
        try {
            // 初始化双核审核通过前对再保数据校验返回信息
            reinsCheckDto.setCerTiNo(cerTiNo);
            if (ReinsConst.CERTITYPE_PRPT.equals(cerTiType)) {
                reinsCheckDto.setCerTiType(cerTiType);
                reinsCheckDto.setStatusType("Y");
                reinsCheckDto.setStatusDesc("再保处理成功");
                checkReinsRetentionData(cerTiNo);
            }else{
                throw new BusinessException(UserExceptionEnum.REINS_CERTI_TYPE.getCode(), UserExceptionEnum.REINS_CERTI_TYPE.getMessage(), this.getClass().getName() + ".checkReinsRetentionData(" + cerTiNo + ")");
            }
        } catch (BusinessException | IllegalAccessException e) {
            log.info("{}校验失败原因:{}",cerTiNo,e.getMessage());
            reinsCheckDto.setStatusType("N");
            reinsCheckDto.setStatusDesc(e.getMessage());
            throw new BusinessException(UserExceptionEnum.REINS_CHECKREINSRETENTIONDATA.getCode(), UserExceptionEnum.REINS_CHECKREINSRETENTIONDATA.getMessage(), this.getClass().getName() + ".checkReinsRetentionData(" + cerTiNo + ")");

        }
        log.info("{}自动核保审核通过前数据校验调出时间：{}", cerTiNo, LocalDateTime.now().format(dateTimeFormatter));
        return reinsCheckDto;
    }

    /**
     * 双核控制再保自留信息查询试算share表
     * @param cerTiNo 承保送再保信息
     * @param cerTiType 校验类型（投保单）
     * @return 返回自留额
     */
    private String shareRetentionValue(String cerTiNo, String cerTiType) {
        long retentionValue;
        //分保试算调用入口
        if(cerTiType.equals(ReinsConst.CERTITYPE_PRPT)){
            //todo 后期调用试算接口表
///            ReinsPolicyUnit reinsPolicyUnit = iReinsPolicyUnitService.selectReinsPolicyUnit(cerTiNo);
///                if(ReinsCompareRiskUtils.isPmlTrialClass(reinsPolicyUnit.getClassCode())){
///                    new BLYJReinsTrialAction().simulateRepolicyByDangerNo(certiNo, "T", dbManager);
///               }else{
///                    new BLReinsTrialAction().simulateRepolicyByDangerNo(certiNo,"T", dbManager);
///                }
            retentionValue = iPrptReinsShareService.sumRetentionValue(cerTiNo);
            log.info("再保自留额：{}", retentionValue);
        }else{
            throw new BusinessException(UserExceptionEnum.REINS_CERTI_TYPE.getCode(), UserExceptionEnum.REINS_CERTI_TYPE.getMessage(), this.getClass().getName() + ".checkReinsData(" + cerTiNo + ")");
        }
        return Long.toString(retentionValue);

    }

    /**
     * 修改日志，删除再保系统数据
     * @param reinsDeleteDto 下发修改对象
     * @param reinsInterFlog 再保日志对象
     */
    private void deletePolicyData(ReinsDeleteDto reinsDeleteDto, ReinsInterFlog reinsInterFlog) {
            // 生成日志表
            try {
                // 查询序号
                Integer amxSerialNo = iReinsInterFlogService.selectMaxSerialNo(reinsDeleteDto.getCerTiNo());
                reinsInterFlog.setSerialNo(amxSerialNo+1);
                // 插入记录
                iReinsInterFlogService.save(reinsInterFlog);
            } catch (BusinessException e) {
                log.error("投保单号：{}日志表生成错误" , reinsDeleteDto.getCerTiNo() );
                throw new BusinessException(UserExceptionEnum.REINS_SAVE_REINSINTERFLOG.getCode(),UserExceptionEnum.REINS_SAVE_REINSINTERFLOG.getMessage());
            }
            // 删除再保数据
            try {
                log.info(">>>>>>>>>>投保单号：{} 下发修改 begin >>>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
                deleteReinsPolicyData(reinsDeleteDto);
                log.info(">>>>>>>>>>投保单号：{} 下发修改 end >>>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
            } catch (BusinessException e) {
                log.error("投保单号：{}下发修改错误" , reinsDeleteDto.getCerTiNo());
                throw new BusinessException(UserExceptionEnum.REINS_DELETE_DELETEREINSPOLICY.getCode(),UserExceptionEnum.REINS_DELETE_DELETEREINSPOLICY.getMessage());
            }
            try {
                log.info(">>>>>>>>>>投保单号：{}更新日志表 begin >>>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
                // 判断是否是见费出单的下发修改
                if (ReinsConst.FLAG_ZERO.equals(reinsDeleteDto.getType())) {
                    reinsInterFlog.setRecordFlag("2");
                } else if (ReinsConst.FLAG_ONE.equals(reinsDeleteDto.getType())) {
                    reinsInterFlog.setRecordFlag("4");
                }
                iReinsInterFlogService.updateById(reinsInterFlog);
                log.info(">>>>>>>>>>投保单号：{}更新日志表 end >>>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
            } catch (BusinessException e) {
                log.error("投保单号：{}日志表生成错误" , reinsDeleteDto.getCerTiNo() );
                throw new BusinessException(UserExceptionEnum.REINS_UPDATE_REINSINTERFLOG.getCode(),UserExceptionEnum.REINS_UPDATE_REINSINTERFLOG.getMessage());
            }




    }

    /**
     * 删除再保系统数据
     * @param reinsDeleteDto 下发修改对象
     */
    private void deleteReinsPolicyData(ReinsDeleteDto reinsDeleteDto) {
        Map<String, Object> columnMap = new HashMap<String, Object>(16) {{
            put("PROPOSALNO", reinsDeleteDto.getCerTiNo());
        }};
        // 删除临分询价表
        log.error(">>>>>>>>下发修改：{}删除询价单信息开始>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
        iFeoEngageService.removeByMap(columnMap);
        iFeoTotService.removeByMap(columnMap);
        iFeoCoinsService.removeByMap(columnMap);
        iFeoItemService.removeByMap(columnMap);
        iFeoReinsReceiveService.removeByMap(columnMap);
        iFeoReinsVerifyService.removeByMap(columnMap);
        iFeoEnquiryService.removeByMap(columnMap);
        log.error(">>>>>>>>下发修改：{}删除询价单信息结束>>>>>>>>>" , reinsDeleteDto.getCerTiNo());

        // 删除超赔信息表 begin
        log.error(">>>>>>>>下发修改：{}删除超赔信息表开始>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
        List<FeoxLayer> feoxLayerList = iFeoxLayerService.listByMap(columnMap);
        String enquiryNo = "";

        if (feoxLayerList != null && feoxLayerList.isEmpty()) {
            for(FeoxLayer feoxLayer : feoxLayerList){
                enquiryNo = feoxLayer.getEnquiryNo();
                break;
            }
            String finalEnquiryNo = enquiryNo;
            Map<String, Object> xColumnMap = new HashMap<String, Object>(16) {{
                put("ENQUIRYNO", finalEnquiryNo);
            }};
            iFeoxPlanService.removeByMap(xColumnMap);
            iFeoxReinsService.removeByMap(xColumnMap);
            iFeoxLayerService.removeByMap(xColumnMap);
        }
        log.error(">>>>>>>>下发修改：{}删除超赔信息表结束>>>>>>>>>" , reinsDeleteDto.getCerTiNo());


        // 删除试算表
        log.error(">>>>>>>>下发修改：{}删除试算信息开始>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
        iPrptReinsShareService.removeByMap(columnMap);
        iPrptReinsTrialService.removeByMap(columnMap);
        log.error(">>>>>>>>下发修改：{}删除试算信息结束>>>>>>>>>" , reinsDeleteDto.getCerTiNo());

        // 删除危险单位
        log.error(">>>>>>>>下发修改：{}删除危险单位信息开始>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
        iPrptDangerCoinsService.removeByMap(columnMap);
        iPrptDangerPlanService.removeByMap(columnMap);
        iPrptDangerTotService.removeByMap(columnMap);
        iPrptDangerItemService.removeByMap(columnMap);
        iPrptDangerUnitService.removeByMap(columnMap);
        log.error(">>>>>>>>下发修改：{}删除危险单位信息结束>>>>>>>>>" , reinsDeleteDto.getCerTiNo());
        // 删除临分分入确认表
        Map<String, Object> prpReinsColumnMap = new HashMap<String, Object>(16) {{
            put("CERTINO", reinsDeleteDto.getCerTiNo());
        }};
        iPrpReinsNotionService.removeByMap(prpReinsColumnMap);
        iPrpReinsVerifyService.removeByMap(prpReinsColumnMap);
        // 删除中间表数据
        iReinsPolicyInterfService.deleteReinsPolicyInterf("PROPOSALNO",reinsDeleteDto.getCerTiNo());

    }

    /**
     * 校验投保单数据
     * @param cerTiNo 业务号
     * @param cerTiType 业务类型
     */
    private void checkReinsData(String cerTiNo, String cerTiType) throws IllegalAccessException {
        if (ReinsConst.CERTITYPE_PRPT.equals(cerTiType)) {
            //自留额，占比数据检查
            checkReinsUnitData(cerTiNo);
            //保证险类、责任险类，自留+附加自留额上限检查
            //todo 试算服务未做，暂时不进行校验
            ///checkReinsRetentionData(cerTiNo);
            //判断是否有临分分出
            checkReinsFeoData(cerTiNo);
            //临分分入确认状态检查
            checkReinsVerifyData(cerTiNo);
        } else {
            throw new BusinessException(UserExceptionEnum.REINS_CERTI_TYPE.getCode(), UserExceptionEnum.REINS_CERTI_TYPE.getMessage(), this.getClass().getName() + ".checkReinsData(" + cerTiNo + ")");
        }
    }

    /**
     * 临分分入确认状态检查
     * @param cerTiNo 业务号
     */
    private void checkReinsVerifyData(String cerTiNo) {
        PrpReinsVerify prpReinsVerify = iPrpReinsVerifyService.findByCerTiNo(cerTiNo);
        ReinsPolicyCeded reinsPolicyCeded = iReinsPolicyCededService.findByProposalNo(cerTiNo);

        if(reinsPolicyCeded!=null ){
            if(prpReinsVerify==null){
                throw new BusinessException(UserExceptionEnum.REINS_REINS_CONFRIM.getCode(), UserExceptionEnum.REINS_REINS_CONFRIM.getMessage(),
                        this.getClass().getName() + ".checkReinsVerifyData(" + cerTiNo + ")");
            }else {
                if(! ReinsConst.FLAG_ONE.equals(prpReinsVerify.getReinsState())){
                    throw new BusinessException(UserExceptionEnum.REINS_FEOENQUIRY_IN_CONFRIM.getCode(), UserExceptionEnum.REINS_FEOENQUIRY_IN_CONFRIM.getMessage(),
                            this.getClass().getName() + ".checkReinsVerifyData(" + cerTiNo + ")");
                }
            }
        }
    }

    /**
     * 判断是否有临分分出
     * @param cerTiNo 业务号
     */
    private void checkReinsFeoData(String cerTiNo){
        QueryWrapper<FeoEnquiry> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("proposalNo",cerTiNo);
        queryWrapper.eq("enquiryType","T");
        List<FeoEnquiry> feoEnquiryList = iFeoEnquiryService.list(queryWrapper);
        if(feoEnquiryList!=null && feoEnquiryList.size()>0){
            for (FeoEnquiry feoEnquiry : feoEnquiryList) {
                if (!"3".equals(feoEnquiry.getVerifyFlag()) && !"9".equals(feoEnquiry.getVerifyFlag())) {
                    throw new BusinessException(UserExceptionEnum.REINS_FEOENQUIRY_OUT_CONFRIM.getCode(), UserExceptionEnum.REINS_FEOENQUIRY_OUT_CONFRIM.getMessage(), this.getClass().getName()+ ".checkReinsFeoData(" + cerTiNo + ")");
                }
            }
        }
    }

    /**
     * 保证险类、责任险类，自留+附加自留额上限检查
     * @param cerTiNo 业务号
     */
    private void checkReinsRetentionData(String cerTiNo) throws IllegalAccessException {
        Map<String, Object> columnMap = new HashMap<String, Object>(16) {{
            put("PROPOSALNO", cerTiNo);
        }};
        List<ReinsPolicyUnit> reinsPolicyUnitList = iReinsPolicyUnitService.listByMap(columnMap);
        for (ReinsPolicyUnit reinsPolicyUnit: reinsPolicyUnitList) {
            if(reinsPolicyUnit==null){
                log.info("校验reinsPolicyUnit为空:{}"+cerTiNo);
            }else{
                double retentionValue = 0D;
                List<PrptReinsShare> prptReinsShareList = iPrptReinsShareService.listByMap(columnMap);
                //TODO 后期试算服务完成后修改这里
///                if(prptReinsShareList == null || prptReinsShareList.size()<=0) {
///                    if(ReinsCompareRiskUtils.isPmlTrialClass(reinsPolicyUnit.getClassCode()))
///                    {
///                        new BLYJReinsTrialAction().simulateRepolicyByDangerNo(cerTiNo, "T");
///                    }else{
///                       new BLReinsTrialAction().simulateRepolicyByDangerNo(cerTiNo,"T");
///                    }
///                    prptReinsShareList = iPrptReinsShareService.listByMap(columnMap);
///                }
                if(prptReinsShareList == null || prptReinsShareList.size()<=0) {
                    throw new BusinessException(UserExceptionEnum.REINS_TRIAL_NOT_EXISTS.getCode(), UserExceptionEnum.REINS_TRIAL_NOT_EXISTS.getMessage());
                } else {
                    for (PrptReinsShare prptReinsShare : prptReinsShareList){
                        if(prptReinsShare.getReinsMode().startsWith("1")){
                            retentionValue += prptReinsShare.getAmount().doubleValue();
                        }
                    }
                    //保证险16
                    if(ReinsCompareRiskUtils.compareRiskToClass(reinsPolicyUnit.getClassCode(), ReinsConst.GUARANTEECLASS)){
                        if(retentionValue >= Double.parseDouble(ReinsConst.GUARANTEERETEN)){
                            throw new BusinessException(UserExceptionEnum.REINS_GUARANTEERETEN_EXCESS.getCode(), UserExceptionEnum.REINS_GUARANTEERETEN_EXCESS.getMessage());
                        }
                    }
                    //责任险12
                    else if(ReinsCompareRiskUtils.compareRiskToClass(reinsPolicyUnit.getClassCode(), ReinsConst.RESPONSIBILITYCLASS)){
                        if(retentionValue >= Double.parseDouble(ReinsConst.RESPONSIBILITYRETEN)){
                            throw new BusinessException(UserExceptionEnum.REINS_RESPONSIBILITYRETEN_EXCESS.getCode(), UserExceptionEnum.REINS_RESPONSIBILITYRETEN_EXCESS.getMessage());
                        }
                    }
                }
            }
        }
    }

    /**
     * 投保单自留额，占比数据检查
     * @param cerTiNo 业务号
     */
    private void checkReinsUnitData(String cerTiNo) {
        Map<String, Object> columnMap = new HashMap<String, Object>(16) {{
            put("PROPOSALNO", cerTiNo);
        }};
        List<PrptDangerUnit> prptDangerUnitList = iPrptDangerUnitService.listByMap(columnMap);
        if (prptDangerUnitList != null && prptDangerUnitList.size() > 0) {
            for (PrptDangerUnit prptDangerUnit : prptDangerUnitList) {
                if (prptDangerUnit.getRetentionValue().equals(BigDecimal.ZERO)) {
                    throw new BusinessException(UserExceptionEnum.REINS_RISK_ASSESSMENT.getCode(),UserExceptionEnum.REINS_RISK_ASSESSMENT.getMessage(), this.getClass().getName() + ".checkReinsUnitData(" + cerTiNo + ")");
                } else if (prptDangerUnit.getDangerShare().doubleValue() != 100) {
                    throw new BusinessException(UserExceptionEnum.REINS_DANGER_SHARE.getCode(), UserExceptionEnum.REINS_DANGER_SHARE.getMessage(), this.getClass().getName() + ".checkReinsUnitData(" + cerTiNo + ")");
                }
            }
        }

    }
}

